<template>
  <div class="container">
    <!-- 顶部栏 -->
    <g-header></g-header>
    <!--广告轮播图-->
    <g-banner1 :img="data.ad.flash_img"></g-banner1>

    <!--主要内容-->
    <div class="main-container">
      <!-- 导航栏 -->
      <g-nav :nav="data.nav" :name="data.belone_menu"></g-nav>
      <!-- 列表容器 -->
      <div class="list-container">
        <!-- 标题栏，有标题和面包屑 -->        
        <div class="title-container">
          <p class="title">{{data.belone_menu}}</p>
          <!-- 面包屑 -->
          <div class="hidden-in-xs breadcrumb">
            <span>当前位置：</span>
            <span>美梦首页></span>
            <span v-for="(item,index) in breadcrumb" :key="index">{{item.cate_name}}{{index==data.breadcrumb.length-1?'':'>'}}</span>
          </div>
        </div>
        <!-- 新闻列表内容 -->
        <div class="item" v-for="(item,index) in data.list.data" :key="index">
          <div class="date hidden-in-xs">
            <span>{{item.update_time.split('-')[2].split(' ')[0]}}</span>{{item.update_time.substr(0,7)}}
          </div>
          <div class="title">
            {{item.news_title}}
          </div>
          <div class="describe">
            {{item.news_describe}}
          </div>
          <router-link :to="'/page/'+item.uid+'/'+$route.params.active">
            <div class="read-more">
              查看详情>>
            </div>
          </router-link>
          <div class="date xs-only">
            {{item.update_time.substr(0,10)}}
          </div>
        </div>
        <!-- 分页栏，因为手机和PC样式不一样，所以只能分开写，这个是PC -->
        <div class="page-container hidden-in-xs">
          共{{data.list.total}}条
          <router-link :to="'../../../newsList/'+$route.params.id+'/1/'+$route.params.active">首页</router-link>
          <router-link v-show="$route.params.page>1" :to="'../../../newsList/'+$route.params.id+'/'+parseInt($route.params.page-1)+'/'+$route.params.active">上一页</router-link>
          第{{data.list.current_page}}页
          <router-link v-show="data.list.last_page!=$route.params.page" :to="'../../../newsList/'+$route.params.id+'/'+parseInt($route.params.page-0+1)+'/'+$route.params.active">下一页</router-link>
          <router-link :to="'../../../newsList/'+$route.params.id+'/'+data.list.last_page+'/'+$route.params.active">末页</router-link>
        </div>
        <!-- 分页栏，因为手机和PC样式不一样，所以只能分开写，这个是手机 -->
        <div class="page-container xs-only">
          <router-link :to="'../../../newsList/'+$route.params.id+'/'+parseInt($route.params.page-1)+'/'+$route.params.active">
            <i class="fas fa-angle-left hidden" v-show="$route.params.page==1"></i>
          </router-link>
          <router-link :to="'../../../newsList/'+$route.params.id+'/'+parseInt($route.params.page-1)+'/'+$route.params.active">
            <i class="fas fa-angle-left" v-show="$route.params.page>1"></i>
          </router-link>

          <input type="number" @keyup.enter="jump" min="1" :max="data.list.last_page" v-model="page" step="1">
          <span>/{{data.list.last_page}}</span>


          <router-link :to="'../../../newsList/'+$route.params.id+'/'+parseInt($route.params.page-0+1)+'/'+$route.params.active">
            <i class="fas fa-angle-right" v-show="data.list.last_page!=$route.params.page"></i>
          </router-link>
          <router-link :to="'../../../newsList/'+$route.params.id+'/'+parseInt($route.params.page-0+1)+'/'+$route.params.active">
            <i class="fas fa-angle-right hidden" v-show="data.list.last_page==$route.params.page"></i>
          </router-link>
        </div>
      </div>
    </div>
    <!-- 底部栏 -->
    <g-footer></g-footer>
  </div>
</template>
<script>
  import header from '@/components/header'
  import banner1 from '@/components/banner1'
  import nav from '@/components/nav'
  import footer from '@/components/footer'
  export default {
    components: {
      'g-header': header,
      'g-banner1': banner1,
      'g-nav': nav,
      'g-footer': footer
    },
    data() {
      return {
        data: {
          list: {
            data: {}
          }
        },
        page: 1
      }
    },
    mounted: function () {
      let that = this;
      this.$axios.get(this.$api+'/api/newsList' + that.getArgs)
        .then(function (response) {
          that.data = response.data;
          that.page = response.data.list.current_page;
        })
        .catch(function (response) {

        });
    },
    methods: {
      /* 调转到下一个上一页，newsList/uid/page/active */
      jump: function () {
        this.$router.push('/newsList/' + this.$route.params.id + '/' + this.page + '/' + this.$route.params.active);
      }
    },
    watch: {
      /**
       * @function 监听地址，如果发生变化（页数改变）,则需要重新请求ajax，渲染
       */
      getArgs: function () {
        let that = this;
        this.$axios.get(this.$api+'/api/newsList' + that.getArgs)
          .then(function (response) {
            that.data = response.data;
            that.page = response.data.list.current_page;
          })
          .catch(function (response) {

          });
      },
    },
    computed: {
      /**
       * @function 根据各个参数生成链接
       */
      getArgs: function () {
        return `?uid=${this.$route.params.id}&page=${this.$route.params.page}`
      },
      /**
       * @function 重新排序面包屑，后台传过来的是倒序
       */
      breadcrumb: function () {
        return this.data.breadcrumb.reverse()
      },
    }
  }

</script>
<style lang="less" scoped>
  @import url('../style/mixin.less');
  .container {
    .main-container {
      width: 1200px;
      margin: 60px auto 0;
      .On-xs( {
        width: calc(100% - 20px);
        margin: 0 10px;
      }
      );
      .list-container {
        width: 900px;
        margin-left: 20px;
        float: left;
        margin-bottom: 65px;
        .On-xs( {
          width: 100%;
          margin-left: 0;
          margin-bottom: 0;
        }
        );
        .title-container {
          border-bottom: 4px solid #a17657;
          height: 76px;
          .On-xs( {
            height: 40px;
            border-bottom: 2px solid #a17657;
          }
          );
          .title {
            float: left;
            height: 76px;
            line-height: 76px;
            font-family: MicrosoftYaHei;
            font-size: 20px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 1px;
            color: #543e2e;
            font-weight: bold;
            .On-xs( {
              font-size: 14px;
              line-height: 40px;
              font-weight: normal;
              font-stretch: normal;
              letter-spacing: 0px;
              color: #543e2e;
              height: 40px;
            }
            );
          }
          .breadcrumb {
            float: right;
            line-height: 76px;
            font-size: 14px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #a17656;
            span:last-child {
              color: #543e2e;
            }
          }

        }
        .item {
          width: 100%;
          height: 140px;
          border-bottom: 1px solid #a17656;
          position: relative;
          .On-xs( {
            max-height: 152px;
            height: 152px;
            width: calc(100% - 40px);
            margin: 0 20px;
          }
          );
          .date {
            width: 120px;
            height: 100%;
            text-align: center;
            float: left;
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            line-height: 140px;
            letter-spacing: 0px;
            color: #a17657;
            .On-xs( {
              width: 50%;
              float: left;
              height: 12px;
              font-size: 12px;
              font-weight: normal;
              font-stretch: normal;
              line-height: 12px;
              letter-spacing: 0px;
              color: #bd9f7f;
              margin-top: 15px;
              text-align: right;
            }
            );
            span {
              height: 140px;
              font-size: 24px;
              line-height: 24px;
              position: absolute;
              top: 29px;
              left: 0;
              width: 120px;
              text-align: center;
            }
          }
          .title {
            width: calc(100% - 29px - 120px);
            height: 19px;
            float: left;
            font-size: 18px;
            font-weight: normal;
            font-stretch: normal;
            line-height: 24px;
            letter-spacing: 0px;
            color: #a17657;
            margin-top: 26px;
            margin-left: 29px;
            text-align: left;
            .On-xs( {
              width: 100%;
              height: 50px;
              text-align: center;
              font-size: 14px;
              line-height: 50px;
              margin: 0;
            }
            );
          }
          .describe {
            width: calc(100% - 29px - 120px);
            height: 19px;
            float: left;
            text-align: left;
            font-size: 14px;
            font-weight: normal;
            font-stretch: normal;
            line-height: 24px;
            letter-spacing: 0px;
            color: #a17657;
            margin-left: 29px;
            margin-top: 13px;
            .Mult-line(1);
            .On-xs( {
              width: 100%;
              height: 54px;
              font-family: MicrosoftYaHei;
              font-size: 13px;
              font-weight: normal;
              font-stretch: normal;
              line-height: 18px;
              letter-spacing: 0px;
              color: #a17656;
              text-align: left;
              margin: 0;
              .Mult-line(3);
            }
            );
          }
          .read-more {
            font-family: MicrosoftYaHei;
            font-size: 14px;
            font-weight: normal;
            font-stretch: normal;
            line-height: 24px;
            letter-spacing: 1px;
            color: #a17657;
            float: right;
            margin-right: 15px;
            margin-top: 21px;
            .On-xs( {
              float: left;
              width: 50%;
              margin: 0;
              font-size: 12px;
              font-weight: normal;
              font-stretch: normal;
              line-height: 12px;
              letter-spacing: 0px;
              color: #a17657;
              text-align: left;
              margin-top: 15px;
            }
            );
          }
        }
        .page-container.hidden-in-xs {
          height: 85px;
          width: 100%;
          float: left;
          font-size: 14px;
          font-weight: normal;
          font-stretch: normal;
          line-height: 24px;
          letter-spacing: 1px;
          color: #543e2e;
          line-height: 125px;
          a {
            .A-all-state( {
              color: #a17657;
              text-decoration: none;
            }
            );
          }
        }
        .page-container.xs-only {
          height: 72px;
          width: 100%;
          font-size: 14px;
          font-weight: normal;
          font-stretch: normal;
          line-height: 72px;
          letter-spacing: 0px;
          color: #a17656;
          i {
            color: #a17656;
            line-height: 72px;
            text-align: center;
            &.hidden {
              color: #eedac5;
            }
          }
          input {
            width: 27px;
            height: 32px;
            border-radius: 4px;
            border: solid 1px #eedac5;
            font-size: 14px;
            font-weight: normal;
            font-stretch: normal;
            line-height: 27px;
            letter-spacing: 0px;
            color: #a17656;
            text-align: center;
          }
        }
      }
    }
  }

</style>
